package com.skyz.wrap.utils;

import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;

public class ViewUtils {
    public static void setHeightBySelfWidth(View view,double ratio){
        view.post(new Runnable() {
            @Override
            public void run() {
                int width = view.getWidth();
                if (width > 0) {
                    view.getLayoutParams().height = (int) (width * ratio);
                }
            }
        });
    }

    public static void setVedioUI(View view,View tv_video_size,double ratio){
        view.post(new Runnable() {
            @Override
            public void run() {
                int width = view.getWidth();
                if (width > 0) {
                    int height= (int) (width * ratio);
                    view.getLayoutParams().height = height;
                    FrameLayout.LayoutParams tvVideoSizeLayoutParams = (FrameLayout.LayoutParams) tv_video_size.getLayoutParams();
                    tvVideoSizeLayoutParams.gravity= Gravity.TOP;
                    int left = (int) (width*Double.valueOf(55)/664);
                    int top = (int) (height*Double.valueOf(160)/344);
                    tvVideoSizeLayoutParams.setMargins(left,top,0,0);
                }

            }
        });
    }
    private static final int MIN_DELAY_TIME= 500; // 两次点击间隔不能少于1000ms
    private static long lastClickTime;
    public static boolean isFastClick() {
        boolean flag = true;
        long currentClickTime = System.currentTimeMillis();
        if ((currentClickTime - lastClickTime) >= MIN_DELAY_TIME) {
            flag = false;
        }
        lastClickTime = currentClickTime;
        return flag;
    }
}
